/*
 * This code is property of CoreObjects. Use, duplication and disclosure
 * in any form without permission of copyright holder is prohibited.
 *
 */

package com.nen.session;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

/**
 *
 * @author amitm
 */
public class ServiceResponse implements Serializable {
    private static final char DELIMITER = '|';
    private Map userInfoMap = new HashMap();

    public ServiceResponse() {
    }

    public Map getUserInfoMap() {
        return userInfoMap;
    }

    public void addField(String name, Object value) {
        userInfoMap.put(name, value);
    }

    public void addFields(Map userInfoMap) {
        this.userInfoMap.putAll(userInfoMap);
    }
    
    @Override
    public String toString() {
        return buildResponseString(userInfoMap);
    }

    private static String buildResponseString(Map userInfoMap){
        StringBuilder builder = new StringBuilder();
        Iterator keyItr = userInfoMap.keySet().iterator();
        while(keyItr.hasNext()) {
            Object key = keyItr.next();
            Object value = userInfoMap.get(key);
            builder.append(key+"="+value);
            if(keyItr.hasNext()) {
                builder.append(DELIMITER);
            }
        }
        return builder.toString();
    }

}
